package com.lxl.priv.csv;

import cn.hutool.crypto.digest.DigestAlgorithm;
import cn.hutool.crypto.digest.Digester;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

/**
 * @Author xiulong.liu
 * @Date 2024/10月/29/星期二 14:16
 * @Desc 13100000000 - 13109999999
 */
public class CreateFile {
    public static void main(String[] args)  throws Exception{
        long start = System.currentTimeMillis();
        File file = new File("F:/test.csv");
        if (file.exists()) {
            file.delete();
        }
        FileWriter fileWriter = new FileWriter(file);
        BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
        CSVPrinter csvPrinter = new CSVPrinter(bufferedWriter, CSVFormat.DEFAULT);
        csvPrinter.printRecord("id");
        long phone = 13300000000L;
        for (int i = 0; i < 10; i++) {
            phone = phone + i;
            String string = String.valueOf(phone);
            //String replace = str.replace(string.length() - 1, string.length(), string);
            String sha256 = new Digester(DigestAlgorithm.SHA256).digestHex(string, "UTF-8");
            csvPrinter.printRecord(sha256);
            int sub = i % 1000000;
            if (sub == 0) {
                csvPrinter.flush();
                System.out.println("写入" + i);
            }
        }
        csvPrinter.flush();
        long end = System.currentTimeMillis();
        System.out.println("end - start = " + (end - start));

    }
}
